<template>
	<view @click="clickFillRecordItem" class="fill-record-item">
		<view class="title">
			<view class="title-text">{{ data.pmName }}</view>
		</view>

		<view class="box-con">
			<view class="box-item">线路名称：{{ data.lineSiteList[0].name }}</view>
			<view class="box-item">区间站点：{{ extractLowestLevelList(data.lineSiteList).map(it => it.name).join(",") }}</view>
			<view class="box-item">开始时间：{{ getDate2(data.constructionStartTime) }}</view>
			<view class="box-item">提交人员：{{ data.creatorUserName }}</view>
		</view>
		<view style="display: flex;align-items: center;justify-content: flex-end;">
			<view class="btn-op" v-if="(data  && data.orderStatus === 'acceptance_status_not_started') && (data  && data.isBindingMonitoringNumber === 0)">
				<view class="op-yellow" @click.stop="clickdelete" :loading="isLoading">删除</view>
				<view class="op-blue" @click.stop="clickSubmit(data)" :loading="isLoading">编辑</view>
			</view>
			<view class="btn-op">
				<view class="op-red" @click.stop="isShowCancel = true" :loading="isLoading" v-if="(data  && data.orderStatus === 'acceptance_status_not_started') && (data  && data.state === 1)">取消</view>
				<view class="op-red" @click.stop="isShowTips = true" :loading="isLoading" v-else>取消</view>
			</view>
		</view>
		<u-modal :show="isShowModal" title="提示" content='此操作将永久删除该数据, 是否继续?'
			showCancelButton :confirmText="'删除'" :confirmColor="'#ff686a'" @confirm="fnDelete(data)" @cancel="isShowModal = false"></u-modal>
		<u-modal :show="isShowTips" title="取消提示" content='该计划下的的条件验收已在进行中或审核中，无法取消'
				:showCancelButton="false"   @confirm="isShowTips = false" ></u-modal>
		<u-modal :show="isShowCancel"  title="取消提示" showCancelButton :confirmText="'提交'" :confirmColor="'#1890ff'" @confirm="$u.throttle(cancelSubmit(data), 2000)" @cancel="cancelButton">
			<view class="slot-content" style="width: 100%;">
				<u--textarea v-model="cancelWhy" placeholder="请输入取消原因" confirmType="done"></u--textarea>
				<view class="" style="margin-top: 30rpx;">注：取消后会有以下影响，请谨慎操作</view>
				<view style="padding-left: 62rpx;margin-top: 30rpx;">1）已绑定的监控设备将自动解绑</view>
				<view style="padding-left: 62rpx;margin-top: 30rpx;">2）生成的未开始的条件验收在app端及web端均不可见</view>
				<view style="padding-left: 62rpx;margin-top: 30rpx;">3）产业大屏【现场管理-施工项目】【现场管理-现场人员】不显示该已取消的计划下的条件验收，不统计相关人员</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import mixins from "@/utils/mixins.js"
	import { constructionPlan_delete, constructionPlan_get,constructionPlan_cancel } from "@/api/engineeringMaintenance/engineeringMaintenance.js";
	export default {
		name: "fill-record-item",
		mixins: [mixins],
		props: {
			/**
			 * 当前组件的类型 
			 * 参考蓝湖地址：https://lanhuapp.com/web/#/item/project/detailDetach?pid=78dfd8f8-40b8-45cc-8521-66aa786384ea&project_id=78dfd8f8-40b8-45cc-8521-66aa786384ea&image_id=8c16eb70-0af1-4b84-81cc-3690028a1985&fromEditor=true
			 * - 0: 没有上传照片按钮的那种  1: 已上传的那种  2: 未上传的那种
			 * */
			type: {
				type: Number,
				default: 0
			},
			/** 数据 */
			data: {
				type: Object,
				default: () => ({}),
			},
			/** 页面的类型 - 0: 综合大修下的  1: 工程维保下的 */
			pageType: {
				type: Number,
				default: 0
			},
		},
		data() {
			return {
				isLoading: false,
				isShowModal:false,
				isShowCancel:false,
				isShowTips:false,
				cancelWhy:''
			}
		},
		methods: {
			/** 点击某一项 */
			clickFillRecordItem() {
				uni.navigateTo({
					url: `/subpackage-plasmosafety/pages/qualitySafetyManagement/dailyConstructionPlan/planDetails?id=${this.data.id}`
				});
			},
			//获取树形数据最后一个list
			extractLowestLevelList(data) {
				let result = [];
				for (let i = 0; i < data.length; i++) {
					if (data[i].list) {
						result = result.concat(this.extractLowestLevelList(data[i].list));
					} else {
						result.push(data[i]);
					}
				}
				return result;
			},
			clickdelete() {
				this.isShowModal = true
			},
			fnDelete(item) {
				constructionPlan_delete({id:item.id}).then(res => {
					uni.showToast({
						title:res.message,
						icon:'none',
						duration:1000
					})
					this.isShowModal = false
					this.$emit('fnGetList')
					// setTimeout(() => {
					// 	uni.navigateBack()
					// },1200)
					
				})
			},
			cancelSubmit(obj) {
				if(!this.cancelWhy) return this.$message('请输入取消原因')
				if(this.isLoading) return
				this.isLoading = true
				constructionPlan_cancel({
					id:obj.id,
					cancelWhy:this.cancelWhy,
					projectId:null
				}).then(res => {
					if(res.success) {
						this.$message(res.message)
						this.cancelButton()	
						this.$emit('fnGetList')
						this.isLoading = false
					}
				}).catch(e => {
					this.cancelButton()	
					this.$emit('fnGetList')
					this.isLoading = false
				})
				
			},
			cancelButton() {
				this.isShowCancel = false
				this.cancelWhy = ''
			},
			async clickSubmit(item) {
				this.isLoading = true
				let obj = await this.getDetailInfo(item.id)
				uni.navigateTo({
					url: `/subpackage-plasmosafety/pages/qualitySafetyManagement/dailyConstructionPlan/index?isEdit=1&editObj=${JSON.stringify(obj)}`
				})
				this.isLoading = false
			},
			getDetailInfo(id){
				return new Promise(async (resolve) => {
					try{
						let res = await constructionPlan_get({id, projectId:null})
						resolve(res.result)
					}catch(e){
						resolve({})
					}
					
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.fill-record-item {
		background: #fff;
		// border-radius: 20upx;
		padding: 20upx 26upx;
		border-bottom: 2rpx solid #E0E7F6;

		.title {
			color: #22204e;
			font-weight: bold;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.title-text {
				line-height: 40upx;
				max-width: 700upx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.box-con {
			margin-top: 16upx;
			line-height: 28upx;
			font-size: 28upx;
			color: #6a819e;

			.box-item {
				margin-left: 4upx;
				margin-top: 16upx;
				line-height: 28upx;
				max-width: 700upx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
		.btn-op {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-top: 10upx;
			.op-red, .op-blue, .op-yellow{
				width: 128upx;
				height: 60upx;
				background: #FF6A6A;
				border-radius: 8upx;
				text-align: center;
				color: white;
				font-size: 28upx;
				font-weight: 500;
				line-height: 60upx;
			}
			.op-yellow {
				background: #f59a23;
			}
			.op-blue {
				background: #2F80ED;
				margin:0 20upx;
			}
		}


	}
</style>